{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "8e44cbfc",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy\n",
    "import pandas\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3490dc30",
   "metadata": {},
   "source": [
    "- sum 求和"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "5ba89309",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "n = numpy.arange(10)\n",
    "n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "0c568d88",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "45"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "numpy.sum(n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "7cedb5fd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[6, 5, 8, 7],\n",
       "       [4, 7, 6, 7],\n",
       "       [7, 0, 9, 0],\n",
       "       [0, 3, 8, 0]])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "n = numpy.random.randint(0,10,size=(4,4))\n",
    "n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "f5d481c0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "77"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "numpy.sum(n) # 所有数的和"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "d11a5291",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([26, 24, 16, 11])"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "numpy.sum(n,axis=1) # 这里axis是选择维度"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e6a46254",
   "metadata": {},
   "source": [
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2eac6d4f",
   "metadata": {},
   "source": [
    "- min 最小值"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e22ed1d3",
   "metadata": {},
   "source": [
    "- max 最大值"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "438a17d5",
   "metadata": {},
   "source": [
    "- mean 平均值"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "208a521a",
   "metadata": {},
   "source": [
    "- average 平均值"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a01e5a10",
   "metadata": {},
   "source": [
    "- median 中位数"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4f199a70",
   "metadata": {},
   "source": [
    "- percentile 百分位数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "01069e61",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "4.5"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "n = numpy.arange(10)\n",
    "display(n)\n",
    "numpy.percentile(n,q=50)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "40283b9d",
   "metadata": {},
   "source": [
    "- argmin 最小值对应的下标"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e0ca8465",
   "metadata": {},
   "source": [
    "- argmax 最大值对应的下标"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "109769d1",
   "metadata": {},
   "source": [
    "- std 标准差"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "845120ea",
   "metadata": {},
   "source": [
    "- var 方差"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8db84d8a",
   "metadata": {},
   "source": [
    "- power 次方，求幂"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8abcb606",
   "metadata": {},
   "source": [
    "- argwhere 按条件查找"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "6a652a3e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 4],\n",
       "       [10]], dtype=int64)"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "n = numpy.array([3,6,2,2,8,7,5,3,1,3,8,2])\n",
    "numpy.argwhere(n==numpy.max(n)) # 返回下标"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5e082813",
   "metadata": {},
   "source": [
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e23c3f98",
   "metadata": {},
   "source": [
    "- nan 数值类型，not a number 不是一个数，表示空。\n",
    "- numpy.nan 是float类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "2c430ffb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "nan"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "n = numpy.array([1,2,3,numpy.nan])\n",
    "numpy.sum(n) # 这里是算不出来的"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "78fcb209",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6.0"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "numpy.nansum(n) # 需要使用这个函数来算，意思是排除掉nan之后，进行计算。"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
